<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="../jQgrid.jsp"%>

</head>
<body style="background-color: white;" class="gray-bg">
                    <div class="ibox-content">
                        <form  class="form-horizontal m-t" id="signupForm">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">公司名称：</label>
                                <div class="col-sm-8">
                                    <input id="depName" name="depName" value="" class="form-control" type="text">
                                    <input name="pid" type="hidden"  value="0" >
                                    <input type="hidden" name="level" value="${level }" />
                                    <input name="state" type="hidden"  value="1" >
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i>公司名是唯一存在</span>
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-3 control-label">所在区域：</label>
                                <div class="col-sm-8 form-inline">
                                    <input type="hidden" id="areaId" name="areaId" />
	                                <select  id="province" name="province"  class="form-control" ></select>
									<select  id="city" name="city"  class="form-control"  style="display:none;" ></select>
									<select  id="county" name="county" class="form-control"  style="display:none;" ></select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">公司地址：</label>
                                <div class="col-sm-8">
                                    <input id="address" name="address" value="" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                                </div>
                            </div>
                          
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button" id="sub">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
	<script>
	$(function(){
		$("#sub").click(function(){
			var depName = $("#depName").val();
			if(depName.length==0){
				$("#depName").tips({
					side:3,
		            msg:'公司名不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#depName").focus();
				return;
			}
			
			if($("#address").val().length==0){
				$("#address").tips({
					side:3,
		            msg:'地址不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#address").focus();
				return;
			}
			$("#signupForm").ajaxSubmit({
	        	url:'<%=contextPath %>/dep/add',
	        	type:'post',
	        	dataType:"json",
	        	success:function(data){
	        		if(data.code==200){
	        			swal({
	        			    title: data.message,
	        			    type: "success",
	        			    showCancelButton: false,
	        			    confirmButtonText: "确定",
	        			    animation:"slide-from-bottom",
	        			    closeOnConfirm: true
	        			},function(){
	        				top.Dialog.close();
	        			});
	        		}else{
	        			swal("错误", data.message, "error");
	        		}
	        	}
	      }); 
		});
		var areaids="";
		var areanames="";
		$.ajax({//查询省
			url:"<%=contextPath%>/area/getAreaJson",
			data:{pid:0,level:1},
			type:"post",
			dataType:"json",
			success:function(data){
				var htm='';
				$("#province").append('<option value="">==请选择省直辖市==</option>');
				$.each(data,function(i,item){
					$("#province").append("<option value='" + item.id + "'>" + item.name + "</option>");
				});
			}
		});	
		$("#province").change(function(){//查询市
			var pid = $(this).val();
			areaids = pid;
			$("#areaId").val(areaids);
			var city = $("#city");
			var county = $("#county");
			$("#city").show();
			$("#county").hide();
			if($("#city").children().length > 0) {
				city.empty();
			}
			if($("#county").children().length > 0) {
				county.empty();
			}
			$.ajax({//查询省
				url:"<%=contextPath%>/area/getAreaJson",
				data:{pid:pid,level:2},
				type:"post",
				dataType:"json",
				success:function(data){
					$("#city").append('<option value="">==请选择市州==</option>');
					$.each(data,function(i,item){
						$("#city").append("<option value='" + item.id + "'>" + item.name + "</option>");
					});
				}
			})
		});
		$("#city").change(function(){//查询市
			var pid = $(this).val();
			areaids +=","+pid;
			$("#areaId").val(areaids);
			var county = $("#county");
			$("#county").show();
			if($("#county").children().length > 0) {
				county.empty();
			}
			$.ajax({//查询省
				url:"<%=contextPath%>/area/getAreaJson",
				data:{pid:pid,level:3},
				type:"post",
				dataType:"json",
				success:function(data){
					$("#county").append('<option value="">==请选择县区==</option>');
					$.each(data,function(i,item){
						$("#county").append("<option value='" + item.id + "'>" + item.name + "</option>");
					});
				}
			})
		});
		$("#county").change(function(){//查询市
			var pid = $(this).val();
			areaids +=","+pid;
			$("#areaId").val(areaids);
		});
		
	});
	
	
	</script>
</body>
</html>